this.BX=this.BX||{};(function(e,t,r,i){"use strict";var n=function(){function e(r,i){babelHelpers.classCallCheck(this,e);this.callbacks=i;this.container=r;var n=r.querySelector("#ui-button-panel-save");if(n){n.addEventListener("click",this.handleSaveButtonClick.bind(this));this.saveButton=t.ButtonManager.createFromNode(n)}var s=r.querySelector("#ui-button-panel-remove");if(s){s.addEventListener("click",this.handleRemoveButtonClick.bind(this));this.removeButton=t.ButtonManager.createFromNode(s)}}babelHelpers.createClass(e,[{key:"handleSaveButtonClick",value:function e(t){var r=this;var n=function e(){r.saveButton.setWaiting(false);i.Dom.removeClass(r.saveButton.getContainer(),"ui-btn-wait")};this.callbacks.onSave().then(n)["catch"](n)}},{key:"handleRemoveButtonClick",value:function e(t){var n=this;var s=function e(){n.removeButton.setWaiting(false);i.Dom.removeClass(n.removeButton.getContainer(),"ui-btn-wait")};r.MessageBox.confirm(i.Loc.getMessage("IBLOCK_PROPERTY_DETAILS_REMOVE_POPUP_MESSAGE"),(function(){n.callbacks.onRemove().then(s)["catch"](s);return true}),null,(function(){s();return true}))}}]);return e}();var s=function(){function e(t){babelHelpers.classCallCheck(this,e);this.errorsWrapper=t.querySelector("#iblock-property-details-errors");this.errorsMessage=this.errorsWrapper.querySelector(".ui-alert-message")}babelHelpers.createClass(e,[{key:"show",value:function e(t){this.errorsMessage.innerHTML=t.map((function(e){return e.message})).join("\n");this.errorsWrapper.style.display="block"}},{key:"hide",value:function e(){this.errorsMessage.innerHTML="";this.errorsWrapper.style.display="none"}}]);return e}();var a=function(){function e(t){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"isProgress",false);this.container=t}babelHelpers.createClass(e,[{key:"getLoader",value:function e(){if(!this.loader){this.loader=new i.Loader({size:150})}return this.loader}},{key:"start",value:function e(){this.isProgress=true;if(!this.getLoader().isShown()){this.getLoader().show(this.container)}}},{key:"stop",value:function e(){this.isProgress=false;this.getLoader().hide()}}]);return e}();var o="iblockPropertyDetails:deferredSlider";var l=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,null,[{key:"getDeferredSlider",value:function e(){var t=top[o];top[o]=null;return t}},{key:"setDeferredSlider",value:function e(t){top[o]=t}}]);return e}();function c(e,t){var r=typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=u(e))||t&&e&&typeof e.length==="number"){if(r)e=r;var i=0;var n=function e(){};return{s:n,n:function t(){if(i>=e.length)return{done:true};return{done:false,value:e[i++]}},e:function e(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s=true,a=false,o;return{s:function t(){r=r.call(e)},n:function e(){var t=r.next();s=t.done;return t},e:function e(t){a=true;o=t},f:function e(){try{if(!s&&r["return"]!=null)r["return"]()}finally{if(a)throw o}}}}function u(e,t){if(!e)return;if(typeof e==="string")return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return d(e,t)}function d(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}function h(e,t){f(e,t);t.add(e)}function f(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function p(e,t,r){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return r}var y=new WeakSet;var v=new WeakSet;var b=function(){function e(t){babelHelpers.classCallCheck(this,e);h(this,v);h(this,y);this.iblockId=t.iblockId;this.propertyId=t.propertyId;this.slidersOptions=t.sliders;this.signedParameters=t.signedParameters;this.detailPageUrlTemplate=t.detailPageUrlTemplate||"";this.container=document.querySelector(t.containerSelector);this.errors=new s(this.container);this.progress=new a(this.container);this.buttons=new n(this.container,{onSave:this.handlerSaveButtonClick.bind(this),onRemove:this.handlerRemoveButtonClick.bind(this)});this.initEvents();this.adjustVisibilityLeftMenu();this.stylizationSettingsControls();BX.UI.Hint.init(this.container);var r=l.getDeferredSlider();if(r){this.openSlider(r)}}babelHelpers.createClass(e,[{key:"initEvents",value:function e(){this.getPropertyTypeInput().addEventListener("change",this.handlePropertyTypeChange.bind(this))}},{key:"getTabs",value:function e(){return this.container.querySelectorAll(".iblock-property-details-tab")}},{key:"getAdditionalTab",value:function e(){return Array.prototype.find.call(this.getTabs(),(function(e){return e.dataset.tab==="additional"}))}},{key:"getPropertyTypeInput",value:function e(){return this.container.querySelector('[name="PROPERTY_TYPE"]')}},{key:"openTab",value:function e(t){var r="iblock-property-details-tab_current";this.getTabs().forEach((function(e){if(e.dataset.tab===t){e.classList.add(r)}else if(e.classList.contains(r)){e.classList.remove(r)}}))}},{key:"openSlider",value:function e(t){var n=this;var s=this.slidersOptions[t];if(!s){throw new Error("Cannot find config for slider '".concat(t,"'"))}if(this.isNewProperty()&&s.newPropertyConfirmMessage){r.MessageBox.confirm(s.newPropertyConfirmMessage,(function(){l.setDeferredSlider(t);n.handlerSaveButtonClick();return true}),i.Loc.getMessage("IBLOCK_PROPERTY_DETAILS_POPUP_OPEN_SLIDER_CONFIRM_SAVE_BUTTON"))}else{top.BX.SidePanel.Instance.open(s.url,s)}}},{key:"handlePropertyTypeChange",value:function e(t){var r=this;if(this.progress.isProgress){return}this.progress.start();this.errors.hide();p(this,y,g).call(this,"getSettings",{propertyFullType:this.getPropertyTypeInput().value}).then((function(e){var t;var n=(t=e.data.info)===null||t===void 0?void 0:t.showedFields;if(i.Type.isArray(n)){r.adjustVisibilityCommonFields(n)}var s="";if(e.data.html&&e.data.html.length>0){s=e.data.html}r.progress.stop();i.Runtime.html(r.getAdditionalTab(),s).then((function(){r.adjustVisibilityLeftMenu();r.stylizationSettingsControls()}))}))["catch"]((function(e){r.progress.stop();r.errors.show(e.errors)}))}},{key:"adjustVisibilityCommonFields",value:function e(t){var r=this.container.querySelector('[data-tab="common"]');if(!r){return}r.querySelectorAll("input, select, textarea").forEach((function(e){if(!e.name||e.name==="PROPERTY_TYPE"){return}var r=e.closest(".iblock-property-details-input");if(t.includes(e.name)){e.disabled=false;if(r){r.style.display=null}}else{e.disabled=true;if(r){r.style.display="none"}}}))}},{key:"adjustVisibilityLeftMenu",value:function e(){var t;var r=(t=this.container.querySelector('[name="PROPERTY_TYPE"]'))===null||t===void 0?void 0:t.value;var i=document.querySelector('#iblock-property-details-sidepanel-menu [data-slider="list-values"]');if(r==="L"){i.style.display="flex"}else{i.style.display="none"}var n=document.querySelector('#iblock-property-details-sidepanel-menu [data-slider="directory-items"]');if(r==="S:directory"){n.style.display="flex"}else{n.style.display="none"}}},{key:"stylizationSettingsControls",value:function e(){var t=["button","submit","reset"];var r=["checkbox","radio"];var i=function e(t){var r=t.parentNode.childNodes;r=Array.prototype.filter.call(r,(function(e){if(e instanceof Text){return e.nodeValue.trim()!==""}return true}));return r.length===1};var n=function e(n){if(n.classList.contains("ui-ctl-element")){return}if(n.nodeName==="INPUT"){var s=n.type||"text";if(t.includes(s)){return}else if(r.includes(s));else if(s==="hidden");else{n.classList.add("ui-ctl-element");if(!i(n)){n.classList.add("ui-ctl-inline")}else{n.classList.add("ui-ctl-w100")}}}else if(n.nodeName==="SELECT"){n.classList.add("ui-ctl-element");if(!i(n)){n.classList.add("ui-ctl-inline")}}else if(n.nodeName==="TEXTAREA"){n.classList.add("ui-ctl-element");n.classList.add("ui-ctl-textarea")}};var s=this.getAdditionalTab().querySelector(".iblock-property-details-settings-table");if(s){s.querySelectorAll("input, select, textarea").forEach(n)}var a=this.getAdditionalTab().querySelector('[name="DEFAULT_VALUE"]');if(a){a.closest(".iblock-property-details-input").querySelectorAll("input, select, textarea").forEach(n)}}},{key:"getFields",value:function e(){var t=new FormData;var r;var i=/^(.+?)(\[.+)$/;var n=new FormData(this.container.querySelector("form"));var s=c(n.entries()),a;try{for(s.s();!(a=s.n()).done;){var o=a.value;var l=o[0];if(r=i.exec(l)){l="fields[".concat(r[1],"]").concat(r[2])}else{l="fields[".concat(l,"]")}t.append(l,o[1])}}catch(e){s.e(e)}finally{s.f()}return t}},{key:"isNewProperty",value:function e(){return parseInt(this.propertyId)===0}},{key:"handlerSaveButtonClick",value:function e(){var t=this;this.progress.start();this.errors.hide();var r=this.getFields();r.append("propertyId",this.propertyId);r.append("iblockId",this.iblockId);r.append("sessid",BX.bitrix_sessid());return p(this,y,g).call(this,"save",r).then((function(e){t.progress.stop();if(e.errors.length>0){t.errors.show(e.errors);return false}p(t,v,m).call(t).close();return true}))["catch"]((function(e){t.progress.stop();t.errors.show(e.errors);return false}))}},{key:"handlerRemoveButtonClick",value:function e(){var t=this;this.progress.start();this.errors.hide();return p(this,y,g).call(this,"delete",{id:this.propertyId}).then((function(e){t.progress.stop();p(t,v,m).call(t).close();return true}))["catch"]((function(e){t.progress.stop();t.errors.show(e.errors);return false}))}}]);return e}();function g(e,t){return i.ajax.runComponentAction("bitrix:iblock.property.details",e,{mode:"class",signedParameters:this.signedParameters,data:t})}function m(){return top.BX.SidePanel.Instance.getTopSlider()}e.PropertyDetails=b})(this.BX.Iblock=this.BX.Iblock||{},BX.UI,BX.UI.Dialogs,BX);
//# sourceMappingURL=script.map.js